﻿using System;
using System.Net;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Documents;
using System.Windows.Ink;
using System.Windows.Input;
using System.Windows.Media;
using System.Windows.Media.Animation;
using System.Windows.Shapes;
using System.Collections.Generic;
using System.Linq;
using Content.Web;

namespace Content
{
    public static class RandomExtension
    {
        public static int GetRandomNumber(int min, int max)
        {
            var random = new Random();

            return random.Next(min, max);
        }

        public static void CallRandom(params Action[] delegates)
        {
            var random = GetRandomNumber(0, delegates.Count() - 1);
            delegates.ElementAt(random).Invoke();
        }

        public static DbUnit LoadRandomUnit(Unit unit, params Func<Unit, DbUnit>[] delegates)
        {
            var random = GetRandomNumber(0, 100);
            var divisor = random % delegates.Count();
            
            return delegates.ElementAt(divisor).Invoke(unit);
        }

        public static T GetRandom<T>(this IQueryable<T> list)
        {
            var random = GetRandomNumber(0, list.Count() - 1);
            return list.ElementAt(random);
        }
    }
}
